package org.baicaixiaozhan.learncommon.controller;

import org.baicaixiaozhan.learncommon.util.accesslimit.AccessWithIPLimiter;
import org.baicaixiaozhan.learncommon.util.accesslimit.AccessWithRateLimiter;
import org.baicaixiaozhan.learncommon.util.accesslimit.AccessWithRedisRateLimiter;
import org.baicaixiaozhan.learncommon.util.annotation.AccessLimit;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 测试 Controller
 *
 * @since 2021/7/1
 * @author baicaixiaozhan
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/XSS")
    public ResponseEntity<Object> testXSS(HttpServletRequest request, String params_1) {
        return ResponseEntity.ok(params_1);
    }


    @AccessLimit(AccessWithRateLimiter.class)
    @GetMapping("/testAccessLimit/guava")
    public ResponseEntity<Object> testAccessLimitWithGuava() {
        return ResponseEntity.ok(Map.of("success", true));
    }


    @AccessLimit(AccessWithRedisRateLimiter.class)
    @GetMapping("/testAccessLimit/redis")
    public ResponseEntity<Object> testAccessLimitWithRedisson() {
        return ResponseEntity.ok(Map.of("success", true));
    }

    @AccessLimit(count = 2, timeOfMinutes = 1, value = AccessWithIPLimiter.class)
    @GetMapping("/testAccessLimit/ip")
    public ResponseEntity<Object> testAccessLimitWithIP() {
        return ResponseEntity.ok(Map.of("success", true));
    }

}
